This notebook will begin looking at clustering methods on the expression of the genes in a single sample of the dataset of interest, from an unbiased approach.

Set Up

# Load libraries
library(magrittr)
library(scater)
library(readr)
library(bluster)
library(ggpubr)
library(pheatmap)

# Set file paths
data_dir <- file.path("results", "Gawad_processed_data")

# Source custom functions script
source(file.path("utils", "clustering-functions.R"))

Read in data

sample_290_normalized <- read_rds(
  file.path(data_dir, "SCPCS000216", "SCPCL000290_miQC_downstream_processed_normalized_reduced_sce.rds"))

Perform clustering

k-means

# Perform k-means clustering
kmeans_cluster_names <- paste0("kcluster", c(2:15))

sample_290_normalized <- kmeans_clustering(
  sample_290_normalized,
  k_range = c(2:15),
  check_stability = TRUE
)

# Plot k-means
kmeans_plot_list <- kmeans_cluster_names %>%
  purrr::map(~ plotReducedDim(sample_290_normalized, dimred = "UMAP", colour_by = .x))

cowplot::plot_grid(plotlist = kmeans_plot_list, ncol = 4)

graph-based, walktrap

# Perform graph-based walktrap clustering
walktrap_cluster_names <-paste0("walktrap_cluster", c(5, 10, 15, 20, 25, 50, 100))

sample_290_normalized <- graph_clustering(
  sample_290_normalized,
  nn_range = c(5, 10, 15, 20, 25, 50, 100),
  weighting_type = "rank",
  cluster_function = "walktrap",
  check_stability = TRUE
)
detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'
# Plot
walktrap_plot_list <- walktrap_cluster_names %>%
   purrr::map(~ plotReducedDim(sample_290_normalized, dimred = "UMAP", colour_by = .x))

cowplot::plot_grid(plotlist = walktrap_plot_list, ncol = 3)

graph-based, louvain

# Perform graph-based louvain clustering
louvain_cluster_names <- paste0("louvain_cluster", c(5, 10, 15, 20, 25, 50, 100))

sample_290_normalized <- graph_clustering(
  sample_290_normalized,
  nn_range = c(5, 10, 15, 20, 25, 50, 100),
  weighting_type = "jaccard",
  cluster_function = "louvain",
  check_stability = TRUE
)
detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'detected tied distances to neighbors, see ?'BiocNeighbors-ties'
# Plot
louvain_plot_list <- louvain_cluster_names %>%
   purrr::map(~ plotReducedDim(sample_290_normalized, dimred = "UMAP", colour_by = .x))


cowplot::plot_grid(plotlist = louvain_plot_list, ncol = 3)

Check cluster validity stats

k-means

# Check the k-means cluster validity stats
kmeans_cluster_validity_df_list <- kmeans_cluster_names %>%
  purrr::map(~ cluster_validity_stats(sample_290_normalized, .x))
Joining, by = "cell_barcode"
Joining, by = "cell_barcode"
Joining, by = "cell_barcode"
Joining, by = "cell_barcode"
Joining, by = "cell_barcode"
Joining, by = "cell_barcode"
Joining, by = "cell_barcode"
Joining, by = "cell_barcode"
Joining, by = "cell_barcode"
Joining, by = "cell_barcode"
Joining, by = "cell_barcode"
Joining, by = "cell_barcode"
Joining, by = "cell_barcode"
Joining, by = "cell_barcode"
names(kmeans_cluster_validity_df_list) <- kmeans_cluster_names
kmeans_cluster_validity_df <- dplyr::bind_rows(kmeans_cluster_validity_df_list,
                                       .id = "kmeans_n")
# Plot the k-means cluster purity
plot_clustering_validity(kmeans_cluster_validity_df, "purity", "maximum", "kmeans_n")

# Plot k-means cluster silhouette
plot_clustering_validity(kmeans_cluster_validity_df, "width", "closest", "kmeans_n")

graph-based, walktrap

# Check the walktrap cluster validity stats
walktrap_cluster_validity_df_list <- walktrap_cluster_names %>%
  purrr::map(~ cluster_validity_stats(sample_290_normalized, .x))
Joining, by = "cell_barcode"
Joining, by = "cell_barcode"
Joining, by = "cell_barcode"
Joining, by = "cell_barcode"
Joining, by = "cell_barcode"
Joining, by = "cell_barcode"
Joining, by = "cell_barcode"
names(walktrap_cluster_validity_df_list) <- walktrap_cluster_names
walktrap_cluster_validity_df <- dplyr::bind_rows(walktrap_cluster_validity_df_list,
                                       .id = "walktrap_n")

# Plot the graph-based walktrap cluster purity
plot_clustering_validity(walktrap_cluster_validity_df, "purity", "maximum", "walktrap_n")

# Plot graph-based walktrap cluster silhouette
plot_clustering_validity(walktrap_cluster_validity_df, "width", "closest", "walktrap_n")

graph-based, louvain

# Check the louvain cluster validity stats
louvain_cluster_validity_df_list <- louvain_cluster_names %>%
  purrr::map(~ cluster_validity_stats(sample_290_normalized, .x))
Joining, by = "cell_barcode"
Joining, by = "cell_barcode"
Joining, by = "cell_barcode"
Joining, by = "cell_barcode"
Joining, by = "cell_barcode"
Joining, by = "cell_barcode"
Joining, by = "cell_barcode"
names(louvain_cluster_validity_df_list) <- louvain_cluster_names
louvain_cluster_validity_df <- dplyr::bind_rows(louvain_cluster_validity_df_list,
                                       .id = "louvain_n")

# Plot the graph-based louvain cluster purity
plot_clustering_validity(louvain_cluster_validity_df, "purity", "maximum", "louvain_n")

# Plot graph-based louvain cluster silhouette
plot_clustering_validity(louvain_cluster_validity_df, "width", "closest", "louvain_n")

Check cluster stability

k-means

# Check and plot cluster stability
kmeans_cluster_names %>%
  purrr::walk(~ plot_cluster_stability(sample_290_normalized, .x))

graph-based, walktrap

walktrap_cluster_names %>%
  purrr::walk(~ plot_cluster_stability(sample_290_normalized, .x))

graph-based, louvain

louvain_cluster_names %>%
  purrr::walk(~ plot_cluster_stability(sample_290_normalized, .x))

Session info

sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.3 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.2.20.so

locale:
 [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
 [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
 [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
[10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   

attached base packages:
[1] stats4    stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] pheatmap_1.0.12             ggpubr_0.4.0               
 [3] bluster_1.4.0               readr_2.1.1                
 [5] scater_1.22.0               ggplot2_3.3.5              
 [7] scuttle_1.4.0               SingleCellExperiment_1.16.0
 [9] SummarizedExperiment_1.24.0 Biobase_2.54.0             
[11] GenomicRanges_1.46.1        GenomeInfoDb_1.30.0        
[13] IRanges_2.28.0              S4Vectors_0.32.3           
[15] BiocGenerics_0.40.0         MatrixGenerics_1.6.0       
[17] matrixStats_0.61.0          magrittr_2.0.1             

loaded via a namespace (and not attached):
 [1] bitops_1.0-7              RColorBrewer_1.1-2        bslib_0.3.1              
 [4] tools_4.1.2               backports_1.4.0           utf8_1.2.2               
 [7] R6_2.5.1                  irlba_2.3.3               vipor_0.4.5              
[10] colorspace_2.0-2          nnet_7.3-16               withr_2.4.3              
[13] tidyselect_1.1.1          gridExtra_2.3             compiler_4.1.2           
[16] BiocNeighbors_1.12.0      DelayedArray_0.20.0       labeling_0.4.2           
[19] sass_0.4.0                scales_1.1.1              stringr_1.4.0            
[22] digest_0.6.29             rmarkdown_2.11            XVector_0.34.0           
[25] pkgconfig_2.0.3           htmltools_0.5.2           sparseMatrixStats_1.6.0  
[28] fastmap_1.1.0             rlang_0.4.12              DelayedMatrixStats_1.16.0
[31] farver_2.1.0              jquerylib_0.1.4           generics_0.1.1           
[34] jsonlite_1.7.2            BiocParallel_1.28.2       dplyr_1.0.7              
[37] car_3.0-12                RCurl_1.98-1.5            BiocSingular_1.10.0      
[40] modeltools_0.2-23         GenomeInfoDbData_1.2.7    Matrix_1.3-4             
[43] Rcpp_1.0.7                ggbeeswarm_0.6.0          munsell_0.5.0            
[46] fansi_0.5.0               abind_1.4-5               viridis_0.6.2            
[49] lifecycle_1.0.1           stringi_1.7.6             yaml_2.2.1               
[52] carData_3.0-4             zlibbioc_1.40.0           flexmix_2.3-17           
[55] grid_4.1.2                parallel_4.1.2            ggrepel_0.9.1            
[58] crayon_1.4.2              lattice_0.20-45           cowplot_1.1.1            
[61] beachmat_2.10.0           splines_4.1.2             hms_1.1.1                
[64] knitr_1.36                pillar_1.6.4              igraph_1.2.9             
[67] ggsignif_0.6.3            ScaledMatrix_1.2.0        glue_1.5.1               
[70] evaluate_0.14             renv_0.14.0               vctrs_0.3.8              
[73] tzdb_0.2.0                gtable_0.3.0              purrr_0.3.4              
[76] tidyr_1.1.4               xfun_0.28                 rsvd_1.0.5               
[79] broom_0.7.10              miQC_1.2.0                rstatix_0.7.0            
[82] viridisLite_0.4.0         tibble_3.1.6              beeswarm_0.4.0           
[85] cluster_2.1.2             ellipsis_0.3.2           
LS0tCnRpdGxlOiAiQ2x1c3RlcmluZyIKYXV0aG9yOiBEYXRhIExhYiBmb3IgQUxTRgpkYXRlOiAyMDIyCm91dHB1dDoKICBodG1sX25vdGVib29rOiAKICAgIHRvYzogdHJ1ZQogICAgdG9jX2Zsb2F0OiB0cnVlCi0tLQoKVGhpcyBub3RlYm9vayB3aWxsIGJlZ2luIGxvb2tpbmcgYXQgY2x1c3Rlcmlu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